package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhReport;
import com.ruoyi.dzzh.service.IDzzhReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 灾情速报Controller
 * 
 * @author cjt
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/dzzh/report")
public class DzzhReportController extends BaseController
{
    @Autowired
    private IDzzhReportService dzzhReportService;

    /**
     * 查询灾情速报列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhReport dzzhReport)
    {
        startPage();
        List<DzzhReport> list = dzzhReportService.selectDzzhReportList(dzzhReport);
        return getDataTable(list);
    }

    /**
     * 导出灾情速报列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:export')")
    @Log(title = "灾情速报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhReport dzzhReport)
    {
        List<DzzhReport> list = dzzhReportService.selectDzzhReportList(dzzhReport);
        ExcelUtil<DzzhReport> util = new ExcelUtil<DzzhReport>(DzzhReport.class);
        util.exportExcel(response, list, "灾情速报数据");
    }

    /**
     * 获取灾情速报详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return AjaxResult.success(dzzhReportService.selectDzzhReportByReportId(reportId));
    }

    /**
     * 新增灾情速报
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:add')")
    @Log(title = "灾情速报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhReport dzzhReport)
    {
        return toAjax(dzzhReportService.insertDzzhReport(dzzhReport));
    }

    /**
     * 修改灾情速报
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:edit')")
    @Log(title = "灾情速报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhReport dzzhReport)
    {
        return toAjax(dzzhReportService.updateDzzhReport(dzzhReport));
    }

    /**
     * 删除灾情速报
     */
    @PreAuthorize("@ss.hasPermi('dzzh:report:remove')")
    @Log(title = "灾情速报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(dzzhReportService.deleteDzzhReportByReportIds(reportIds));
    }
}
